/* eslint-disable prettier/prettier */
import { BasicColumn, FormSchema } from '@/components/Table';
import { defHttp } from '@/utils/http/axios';
import { ifShow, ifDescription } from '@/utils/schema_util'
/**
 * 表格列配置
 */
export const tableColumns: BasicColumn[] = [
  {
    title: '所属分组',
    dataIndex: 'schemaGroupId',
    component: 'ApiSelect',
    componentProps: {
      api: "/dev/schemaGroup/select",
      labelField: "name",
      valueField: "id",
      immediate: true,
      placeholder: "请选择所属分组",
    }
  },
  {
    title: '表名称',
    dataIndex: 'tableName',
    component: 'Input',
    componentProps: {
      placeholder: "请输入表名称",
    }
  },
  {
    title: '表注释',
    dataIndex: 'remark',
    component: 'Input',
    componentProps: {
      placeholder: "请输入表注释",
    }
  },
  {
    title: '表类型',
    dataIndex: 'tableType',
    component: 'ApiDict',
    componentProps: {
      code: "dev_schema_table_type",
      dataType: "number",
      placeholder: "请选择表类型",
    }
  },
  {
    title: '图标',
    dataIndex: 'icon',
    component: 'IconPicker',
    componentProps: {
      copy: false,
      placeholder: "请输入图标",
    }
  },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
    component: 'Input'
  },
  {
    title: '操作',
    dataIndex: '__ACTION__',
  },
];
/**
 * 搜索表单配置
 */
export const searchFormSchemas: FormSchema[] = [
  {
    label: '表名称',
    field: 'm_LIKE_tableName',
    component: 'Input',
    componentProps: {
      placeholder: "请输入表名称",
    } as any,
    colProps: { span: 6 },
  },
  {
    label: '表注释',
    field: 'm_LIKE_remark',
    component: 'Input',
    componentProps: {
      placeholder: "请输入表注释",
    } as any,
    colProps: { span: 6 },
  },
  {
    label: '表类型',
    field: 'm_IN_tableType',
    component: 'ApiDict',
    componentProps: {
      placeholder: "请输入表类型",
      code: 'dev_schema_table_type',
      mode: 'multiple',
    } as any,
    colProps: { span: 6 },
  },
  
];

/**
 * 新增、编辑表单配置
 */
export const formSchemas: FormSchema[] = [
  {
    field: 'baseinfo',
    label: '基本信息',
    component: 'Divider',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"Divider_dashed":false,"Divider_plain":false}
      return ifDescription(data,ext);
    },
    componentProps: {
      dashed: false,
      plain: false,
      placeholder: "请输入基本信息",
    } as any,
    required: false,
    colProps: { span: 24 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"Divider_dashed":false,"Divider_plain":false}
      return ifShow(data,ext);
    },
  },
  {
    field: 'id',
    label: '主键',
    component: 'Input',
    show: false,
    description: false,
    componentProps: {
      type: "hidden",
      placeholder: "请输入主键",
    } as any,
    required: false,
    colProps: { span: 24 },
    ifShow: (data) => {
      const ext = {"addHide":1,"editHide":0,"listHide":1,"viewHide":1,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"Input_type":"hidden"}
      return ifShow(data,ext);
    },
  },
  {
    field: 'tableName',
    label: '表名称',
    component: 'Input',
    description: (data) => {
      const ext = {"searchType":"LIKE","addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":1,"span":12}
      return ifDescription(data,ext);
    },
    componentProps: {
      placeholder: "请输入表名称",
    } as any,
    required: true,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"searchType":"LIKE","addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":1,"span":12}
      return ifShow(data,ext);
    },
  },
  {
    field: 'remark',
    label: '表注释',
    component: 'Input',
    description: (data) => {
      const ext = {"searchType":"LIKE","addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":1,"span":12}
      return ifDescription(data,ext);
    },
    componentProps: {
      placeholder: "请输入表注释",
    } as any,
    required: true,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"searchType":"LIKE","addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":1,"span":12}
      return ifShow(data,ext);
    },
  },
  {
    field: 'schemaGroupId',
    label: '所属分组',
    component: 'ApiSelect',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12,"ApiSelect_api":"/dev/schemaGroup/select","ApiSelect_labelField":"name","ApiSelect_valueField":"id","ApiSelect_immediate":true,"popupContainerInBody":false}
      return ifDescription(data,ext);
    },
    componentProps: {
      cacheKey: "dev:schemaGroup:select",
      api: (params) => {
        return defHttp.post({ url: '/dev/schemaGroup/select', params });
      },
      labelField: "name",
      valueField: "id",
      immediate: true,
      placeholder: "请选择所属分组",
    } as any,
    required: false,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12,"ApiSelect_api":"/dev/schemaGroup/select","ApiSelect_labelField":"name","ApiSelect_valueField":"id","ApiSelect_immediate":true,"popupContainerInBody":false}
      return ifShow(data,ext);
    },
  },
  {
    field: 'tableType',
    label: '表类型',
    component: 'ApiDict',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12,"ApiDict_code":"dev_schema_table_type","ApiDict_dataType":"number","popupContainerInBody":false}
      return ifDescription(data,ext);
    },
    componentProps: {
      code: "dev_schema_table_type",
      dataType: "number",
      placeholder: "请选择表类型",
    } as any,
    required: false,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12,"ApiDict_code":"dev_schema_table_type","ApiDict_dataType":"number","popupContainerInBody":false}
      return ifShow(data,ext);
    },
  },
  {
    field: 'formType',
    label: '表单类型',
    component: 'ApiDict',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12,"ApiDict_code":"dev_schema_form_type","ApiDict_dataType":"number","popupContainerInBody":false}
      return ifDescription(data,ext);
    },
    componentProps: {
      code: "dev_schema_form_type",
      dataType: "number",
      placeholder: "请选择表单类型",
    } as any,
    required: false,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12,"ApiDict_code":"dev_schema_form_type","ApiDict_dataType":"number","popupContainerInBody":false}
      return ifShow(data,ext);
    },
  },
  {
    field: 'isTree',
    label: '是否树',
    component: 'ApiDict',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12,"ApiDict_code":"yes_no","ApiDict_dataType":"number","popupContainerInBody":false}
      return ifDescription(data,ext);
    },
    defaultValue: 0,
    componentProps: {
      code: "yes_no",
      dataType: "number",
      placeholder: "请选择是否树",
    } as any,
    required: false,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12,"ApiDict_code":"yes_no","ApiDict_dataType":"number","popupContainerInBody":false}
      return ifShow(data,ext);
    },
  },
  {
    field: 'sort',
    label: '排序',
    component: 'InputNumber',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12}
      return ifDescription(data,ext);
    },
    defaultValue: "99",
    componentProps: {
      placeholder: "请输入排序",
    } as any,
    required: false,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12}
      return ifShow(data,ext);
    },
  },
  {
    field: 'icon',
    label: '图标',
    component: 'IconPicker',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12,"IconPicker_copy":false}
      return ifDescription(data,ext);
    },
    componentProps: {
      copy: false,
      placeholder: "请输入图标",
    } as any,
    required: false,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12,"IconPicker_copy":false}
      return ifShow(data,ext);
    },
  },
  {
    field: 'otherRemark',
    label: '额外说明',
    component: 'InputTextArea',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"InputTextArea_showCount":true}
      return ifDescription(data,ext);
    },
    componentProps: {
      showCount: true,
      placeholder: "请输入额外说明",
    } as any,
    required: false,
    colProps: { span: 24 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"InputTextArea_showCount":true}
      return ifShow(data,ext);
    },
  },
  {
    field: 'layoutProp',
    label: '布局属性',
    component: 'Divider',
    componentProps: {
      dashed: false,
      plain: false,
    },
    colProps: { span: 24 },
  },
  {
    field: 'ext.layout',
    label: '表单布局',
    component: 'Select',
    colProps: {
      span: 12,
    },
    componentProps: {
      placeholder: '请选择表单布局',
      options: [
        { label: '水平', value: 'horizontal' },
        { label: '垂直', value: 'vertical' },
        { label: '内联', value: 'inline' },
      ],
    },
  },
  {
    field: 'ext.searchLayout',
    label: '搜索表单布局',
    component: 'Select',
    colProps: {
      span: 12,
    },
    componentProps: {
      placeholder: '请选择表单布局',
      options: [
        { label: '水平', value: 'horizontal' },
        { label: '垂直', value: 'vertical' },
        { label: '内联', value: 'inline' },
      ],
    },
  },
  {
    field: 'ext.labelWidth',
    label: '标签宽度',
    component: 'Input',
    colProps: {
      span: 12,
    },
    componentProps: {
      placeholder: '请输入标签宽度'
    },
  },
  {
    field: 'ext.labelAlign',
    label: '标签对齐',
    component: 'Select',
    colProps: {
      span: 12,
    },
    componentProps: {
      placeholder: '请选择对齐方式',
      options: [
        { label: '左对齐', value: 'left' },
        { label: '右对齐', value: 'right' },
      ],
    },
  },
  {
    field: 'ext.searchLabelWidth',
    label: '搜索标签宽度',
    component: 'Input',
    colProps: {
      span: 12,
    },
    componentProps: {
      placeholder: '请输入标签宽度'
    },
  },
  {
    field: 'ext.searchLabelAlign',
    label: '搜索标签对齐',
    component: 'Select',
    colProps: {
      span: 12,
    },
    componentProps: {
      placeholder: '请选择搜索对齐方式',
      options: [
        { label: '左对齐', value: 'left' },
        { label: '右对齐', value: 'right' },
      ],
    },
  },
  {
    field: 'extProp',
    label: '扩展属性',
    component: 'Divider',
    colProps: {span: 24},
  },
  {
    field: 'ext.title',
    label: '菜单标题',
    component: 'Input',
    colProps: {span: 24},
    componentProps: {
      placeholder: '请输入菜单标题'
    },
  },
  {
    field: 'ext.relMainTableIdKey',
    label: '关联主表Key',
    component: 'Input',
    colProps: {span: 24},
    ifShow({ values }){
      return values.tableType == 3
    },
    description({ values }){
      return values.tableType == 3
    },
    componentProps: {
      placeholder: '请输入关联主表Key'
    },
  },
  {
    field: 'ext.async',
    label: '异步元数据',
    component: 'RadioGroup',
    colProps: {
      span: 6
    },
    defaultValue: true,
    helpMessage:["当为异步时，进入页面会通过接口重新获取元数据","当为同步时，只使用代码生成的本地元数据"],
    componentProps: {
      isBtn: true,
      options: [{
        label: '异步',
        value: true,
      }, {
        label: '同步',
        value: false,
      }]
    } as any,
  },
  {
    field: 'ext.hideMenu',
    label: '隐藏菜单',
    component: 'RadioGroup',
    colProps: {
      span: 6
    },
    componentProps: {
      isBtn: true,
      options: [{
        label: '隐藏',
        value: true,
      }, {
        label: '显示',
        value: false,
      }]
    } as any,
  },
  {
    field: 'ext.ignoreSync',
    label: '忽略同步',
    component: 'RadioGroup',
    colProps: {
      span: 6
    } as any,
    componentProps: {
      isBtn: true,
      options: [{
        label: '是',
        value: true,
      }, {
        label: '否',
        value: false,
      }]
    } as any,
  },
  {
    field: 'ext.isCreateRoute',
    label: '是否生成路由',
    component: 'RadioGroup',
    colProps: {
      span: 6
    },
    componentProps: {
      isBtn: true,
      options: [{
        label: '是',
        value: true,
      }, {
        label: '否',
        value: false,
      }]
    } as any,
  },
  {
    field: 'ext.defaultAuthTypeList',
    label: '默认功能权限',
    helpMessage: ['模板可根据该配置生成对应功能，同时生成对应的路由权限按钮'],
    labelWidth: '120px',
    component: 'Select',
    colProps: {
      span: 24,
    },
    defaultValue: [
      "list",
      "save",
      "remove",
      "update",
      "detail",
      "export",
      "advSearch",
      "importTo",
      "downloadImportTemplate"
    ],
    componentProps: {
      mode: "tags",
      getPopupContainer: () => document.body,
      options: [
        {
          label: "列表",
          value: "list"
        },
        {
          label: "新增",
          value: "save"
        },
        {
          label: "删除",
          value: "remove"
        },
        {
          label: "编辑",
          value: "update"
        },
        {
          label: "详情",
          value: "detail"
        },
        {
          label: "导出",
          value: "export"
        },
        {
          label: "高级搜索",
          value: "advSearch"
        },
        {
          label: "导入",
          value: "importTo"
        },
        {
          label: "下载模板",
          value: "downloadImportTemplate"
        }
      ]
    }
  },
  {
    field: 'ext.customAuthTypeList',
    label: '自定义功能权限',
    helpMessage: ['和默认功能权限一起，生成对应的路由权限按钮'],
    labelWidth: '120px',
    component: 'CustomAuthTypeList' as any,
    colProps: {
      span: 24
    },
  },
  {
    field: 'ext.customApiList',
    label: '自定义接口',
    helpMessage: ['在原有的crud接口基础上追加接口'],
    labelWidth: '120px',
    component: 'CustomApiList' as any,
    colProps: {
      span: 24
    },
  },
  {
    field: 'ext.actions',
    label: '操作按钮配置',
    labelWidth: '120px',
    component: 'MTableAction' as any,
    colProps: {
      span: 24
    },
  },
];
